/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.math;

/**
 *
 * @author Pieman
 */
public class Vector2 {
    
    public float x;
    public float y;

    public Vector2() {
        x = 0;
        y = 0;
    }

    public Vector2(float x, float y) {
        this.x = x;
        this.y = y;
    }
    
    public Vector2(Vector2 v) {
        this.x = v.x;
        this.y = v.y;
    }
    
    public void set(float x, float y) {
        this.x = x;
        this.y = y;
    }
    
    public float[] toArray() {
        return new float[] {x, y};
    }
    
    public float lengthSquared() {
        return x*x + y*y;
    }
    
    public float length() {
        return (float)Math.sqrt(lengthSquared());
    }
    
    public Vector2 normalised() {
        float l = length();
        return new Vector2(x / l, y / l);
    }
    
    public Vector2 add(Vector2 v) {
        return new Vector2(x + v.x, y + v.y);
    }
    
    public Vector2 subtract(Vector2 v) {
        return new Vector2(x - v.x, y - v.y);
    }
    
    public Vector2 multiply(float f) {
        return new Vector2(x * f, y * f);
    }
    
    public Vector2 multiply(Vector2 v) {
        return new Vector2(x * v.x, y * v.y);
    }
    
    public Vector2 divide(float f) {
        return new Vector2(x / f, y / f);
    }
    
    public Vector2 divide(Vector2 v) {
        return new Vector2(x / v.x, y / v.y);
    }
    
    public float dot(float f) {
        return x*f + y*f;
    }
    
    public float dot(Vector2 v) {
        return x*v.x + y*v.y;
    }
    
    public boolean equals(Vector2 v) {
        return x == v.x && y == v.y;
    }
    
    public Vector2 inversed() {
        return new Vector2(-x, -y);
    }
}
